package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Room;
import com.ruoyi.system.mapper.RoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.NurseMapper;
import com.ruoyi.system.domain.Nurse;
import com.ruoyi.system.service.INurseService;
import com.ruoyi.common.core.text.Convert;

/**
 * 医护信息Service业务层处理
 * 
 * @author 王帅
 * @date 2024-08-24
 */
@Service
public class NurseServiceImpl extends ServiceImpl<NurseMapper,Nurse> implements INurseService

{
    @Autowired
    private NurseMapper nurseMapper;
    @Autowired
    private RoomMapper roomMapper;

    /**
     * 查询医护信息
     * 
     * @param id 医护信息主键
     * @return 医护信息
     */
    @Override
    public Nurse selectNurseById(Long id)
    {
        return nurseMapper.selectNurseById(id);
    }

    /**
     * 查询医护信息列表
     * 
     * @param nurse 医护信息
     * @return 医护信息
     */
    @Override
    public List<Nurse> selectNurseList(Nurse nurse)
    {
        return nurseMapper.selectNurseList(nurse);
    }

    /**
     * 新增医护信息
     * 
     * @param nurse 医护信息
     * @return 结果
     */
    @Override
    public int insertNurse(Nurse nurse)
    {
        nurse.setCreateTime(DateUtils.getNowDate());
        nurse.setUpdateTime(DateUtils.getNowDate());
        Long chargeRoom = nurse.getChargeRoom();
        Room room = roomMapper.selectRoomById(chargeRoom);
        nurse.setRoomNumber(room.getRoomNumber());
        return nurseMapper.insertNurse(nurse);
    }

    /**
     * 修改医护信息
     * 
     * @param nurse 医护信息
     * @return 结果
     */
    @Override
    public int updateNurse(Nurse nurse)
    {
        nurse.setUpdateTime(DateUtils.getNowDate());
        nurse.setUpdateTime(DateUtils.getNowDate());
        Long chargeRoom = nurse.getChargeRoom();
        Room room = roomMapper.selectRoomById(chargeRoom);
        nurse.setRoomNumber(room.getRoomNumber());
        return nurseMapper.updateNurse(nurse);
    }

    /**
     * 批量删除医护信息
     * 
     * @param ids 需要删除的医护信息主键
     * @return 结果
     */
    @Override
    public int deleteNurseByIds(String ids)
    {
        return nurseMapper.deleteNurseByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除医护信息信息
     * 
     * @param id 医护信息主键
     * @return 结果
     */
    @Override
    public int deleteNurseById(Long id)
    {
        return nurseMapper.deleteNurseById(id);
    }
}
